<?
ob_start();
include("common/header.html");
include("common/left.html");
$out_html=ob_get_contents();
ob_end_clean();
include("common/page.php");
if($_SESSION['memberID']!=1 && !($_SESSION['sid']==1 && strpos($_SESSION['qx'],'refund'))){
    exit("无访问权限");
}
$currentPage=$_REQUEST["currentPage"]?$_REQUEST["currentPage"]:1;
$pageSize=$_REQUEST['pageSize']?$_REQUEST["pageSize"]:10;
$offset=($currentPage-1)*$pageSize;
$r=array();
$where=" where 1=1 ";
if($dname=mysql_real_escape_string(trim($_REQUEST['dname']))){
	$where=" where m.dname like '%$dname%'";
}
if($mid=mysql_real_escape_string(trim($_REQUEST['mid']))){
		$where=" where m.id=$mid";
}
$time=$_REQUEST['time'];
if($_REQUEST['btime']){
	$where.=" and $time>='".mysql_real_escape_string($_REQUEST['btime'])." 00:00:00'";
}
if($_REQUEST['etime']){
	$where.=" and $time<='".mysql_real_escape_string($_REQUEST['etime'])." 23:59:59'";
}

// 导出
if($_REQUEST['act']=='Export'){
	$offset = 0 ;
	$pageSize = 9999999;
}
$str="select w.*,m.dname,m.id as memberID,m.fee_bank,m.account,wd_time from pft_wd_cash w left join pft_member m on m.id=w.fid $where order by w.wd_status,w.apply_time desc   limit $offset,$pageSize";
$GLOBALS['le']->query($str);
while($row=$GLOBALS['le']->fetch_assoc()){
	// $row['tfee'] = $row['wd_money']<=40000 ? 2 : $row['wd_money']/20000;  
    if($row['apply_time']>"2015-03-01 00:00:00"){        
        if($row['fee_bank_once']>0)	
        {$row['tfee'] = $row['wd_money']*$row['fee_bank_once']/100000 < 1? 1 : $row['wd_money']*$row['fee_bank_once']/100000;}
		elseif($row['fee_bank_once']==0)
		 {$row['tfee']==0;}
    }else{        
        $row['tfee'] = $row['wd_money']<40000 ? 2 : $row['wd_money']/20000;
    }    
    $row['tfee'] = strpos($row['tfee'] ,'.') ? substr($row['tfee'],0,strpos($row['tfee'],'.')) : $row['tfee'];
    $r[] = $row; 
}
//print_r($r[0]);
$wd_statusT=array(
	0=>"处理中",
	1=>"已完成",
	2=>"已退回",
	3=>"已取消"
);
// 导出
if(isset($_REQUEST['act']) && $_REQUEST['act']=="Export")
{
	$Excel = array();
	$filename=date('YmdHis').'提现申请列表';
	$Excel[0]['a']='银行名称/收款账号(户名)';
	$Excel[0]['b']='金额(元)';
	$Excel[0]['c']='手续费';
	$Excel[0]['d']='转账金额';
	$Excel[0]['e']='处理人员';
	$Excel[0]['f']='申请时间';
	$Excel[0]['g']='备注';
	$Excel[0]['h']='处理进度';
	$i=1;
	foreach($r as $lid=>$row){
		$n++;
		$Excel[$n]['a']=$row['bank_name'].'：'.$row['bank_accuont'];
		$Excel[$n]['b']=$row['wd_money']/100;
		$Excel[$n]['c']=floor($row['tfee']/100);
		$Excel[$n]['d']=$row['wd_money']/100-floor($row['tfee']/100);
		$Excel[$n]['e']=$row['wd_operator']?$row['wd_operator']:'管理员';
		$Excel[$n]['f']=$row['apply_time'];
		$Excel[$n]['g']=$row['memo'];
		$Excel[$n]['h']=$wd_statusT[$row['wd_status']];
	}
	$xls = new SimpleExcel('UTF-8', true,'orderList');
    $xls->addArray($Excel);
    $xls->generateXML($filename);
	exit;
}

echo $out_html;
$str="select count(*) as total from pft_wd_cash w left join pft_member m on m.id=w.fid $where";
$GLOBALS['le']->query($str);
$GLOBALS['le']->fetch_assoc();
$total=$GLOBALS['le']->f('total');
$wd_statusT=array(
	0=>"<font color='orange'>处理中</font>",
	1=>"<font color='green'>已完成</font>",
	2=>"<font color='red'>已退回</font>",
	3=>"<font color='red'>已取消</font>"
);
include("tpl/refund.tpl");
include("common/footer.html");
?>
